package com.kogi.androidpatt.dealing;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.content.ContextWrapper;


import com.kogi.patterns.R;

public class FileLoader extends Activity{
	
	Context myContext;
	ArrayList<String> flags;
	ArrayList<String> names;
	
	public FileLoader(Context con){
		
		myContext = con;
		flags = new ArrayList<String>();
		names = new ArrayList<String>();
		
	}
	
	public ArrayList<String> getNames(){
		return names;
	}
	
	public ArrayList<String> getFlags(){
		return flags;
	}
	
	public void readFileLatitude(){
		InputStream in;
  	  	
      	ContextWrapper Fcont=(ContextWrapper) myContext;
  		in= Fcont.getResources().openRawResource(R.raw.country_latitude);
      	
      	
  		try {
  			
  			 	//StringBuffer inLine = new StringBuffer();
      	        InputStreamReader isr = new InputStreamReader(in);
      	 
      	        BufferedReader inRd = new BufferedReader(isr);
      	      String text;
      	      
      	       	      
      	          
      	        while ((text = inRd.readLine()) != null) {
      	           
      	         //String line[]= text.split(","); 
      	         //flags.add(line[1]);
      	         names.add(text); 
      	         
      	       	      	            
      	        }
      	        in.close();
      	        
  		} catch (FileNotFoundException e) {
  			// TODO Auto-generated catch block
  			e.printStackTrace();
  		} catch (IOException e) {
  			// TODO Auto-generated catch block
  			e.printStackTrace();
  		}
	}
	
	public void readFiles(int ID){
		 InputStream in;
	  	  	
	      	ContextWrapper Fcont=(ContextWrapper) myContext;
	  		in= Fcont.getResources().openRawResource(R.raw.coutries_flags);
	      	
	      	
	  		try {
	  			
	  			 	//StringBuffer inLine = new StringBuffer();
	      	        InputStreamReader isr = new InputStreamReader(in);
	      	 
	      	        BufferedReader inRd = new BufferedReader(isr);
	      	      String text;
	      	      
	      	       	      
	      	          
	      	        while ((text = inRd.readLine()) != null) {
	      	           
	      	         String line[]= text.split(";"); 
	      	         flags.add(line[1]);
	      	         names.add(line[0]); 
	      	         
	      	       	      	            
	      	        }
	      	        in.close();
	      	        
	  		} catch (FileNotFoundException e) {
	  			// TODO Auto-generated catch block
	  			e.printStackTrace();
	  		} catch (IOException e) {
	  			// TODO Auto-generated catch block
	  			e.printStackTrace();
	  		}
	      }
	

}
